<?php
$this->breadcrumbs = array(
    'MLM System',
    'Members' => array('list'),
    'List',
);

$this->menu = array();

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('sys-member-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>
<?php if (Yii::app()->user->hasFlash('success')): ?>
    <div class="alert alert_grey">
        <img height="24" width="24" src="<?php echo Yii::app()->params['backendUrl']; ?>/images/icons/small/grey/success.png">
        <?php echo Yii::app()->user->getFlash('success'); ?>
    </div>
<?php endif; ?>
<?php if (Yii::app()->user->hasFlash('error')): ?>
    <div class="alert alert_grey">
        <img height="24" width="24" src="<?php echo Yii::app()->params['backendUrl']; ?>/images/icons/small/grey/alert_2.png">
        <?php echo Yii::app()->user->getFlash('error'); ?>
    </div>
<?php endif; ?>
<div class="flat_area grid_16">
    <h2>List of Members</h2>
</div>
<div class="box grid_16 round_all">
    <h2 class="box_head grad_colour round_all">Advanced Search</h2>
    <a href="#" class="grabber">&nbsp;</a>
    <a href="#" class="toggle toggle_closed">&nbsp;</a>
    <div class="toggle_container" style="display:none;">
        <?php
        $this->renderPartial('_search', array(
            'model' => $model,
        ));
        ?>
    </div>
</div>
<!-- search-form -->
<?php
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'sys-member-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        array(
            'header' => 'No.',
            'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)."."',
            'htmlOptions' => array('style' => 'text-align:center;'),
        ),
        array(
            'header' => 'Member Id',
            'name' => 'network_mid',
            'value' => 'sys_network::Model()->FindByPk($data->member_network_id)->network_mid',
        ),
        array(
            'name' => 'member_name',
            'value' => '$data->member_name',
        ),
        array(
            'name' => 'member_nickname',
            'value' => '$data->member_nickname',
        ),
        array(
            'header' => 'Sponsor ID',
            'name' => 'sponsor_network_id',
            //'value' => 'sys_network::Model()->FindByPk(sys_network::Model()->FindByPk($data->member_network_id)->network_sponsor_network_id)->network_mid',
            'value' => 'function_lib::get_network_mid(sys_network::Model()->FindByPk($data->member_network_id)->network_sponsor_network_id)',
        ),
        array(
            'name' => 'member_serial_id',
            'value' => '$data->member_serial_id',
            'htmlOptions' => array('style' => 'text-align:center;'),
        ),
        array(
            'name' => 'rel_member_to_serial.serial_pin',
            'value' => 'sys_serial::Model()->FindByPk($data->member_serial_id)->serial_pin',
            'htmlOptions' => array('style' => 'text-align:center;'),
        ),
        array(
            'name' => 'member_join_datetime',
            'value' => '$data->member_join_datetime',
        ),
        array(
            'name' => 'member_is_suspended',
            'type' => 'image',
            'value' => '($data->member_is_suspended == 0 ? Yii::app()->request->baseUrl . "/images/icon/b_ok.png" : Yii::app()->request->baseUrl . "/images/icon/b_notok.png")',
            'filter' => CHtml::activeDropDownList($model, 'member_is_suspended', array('' => '', '1' => 'Not Suspended', '0' => 'Suspended')),
            'htmlOptions' => array('style' => 'text-align:center;'),
        ),
        array(
            'header' => 'Action',
            'class' => 'CButtonColumn',
            'template' => '{view}{update}{password}{login}{report}',
            'buttons' => array(
                'view' => array(
                    'imageUrl' => Yii::app()->request->baseUrl . '/images/icon/adm_detail_navy.png',
                ),
                'update' => array(
                    'imageUrl' => Yii::app()->request->baseUrl . '/images/icon/adm_edit_navy.png',
                ),
                'password' => array(
                    'label' => 'Password Update',
                    'imageUrl' => Yii::app()->request->baseUrl . '/images/icon/adm_key_navy.png',
                    'url' => 'Yii::app()->createUrl("admin/system/member/password", array("id" => sys_network::Model()->FindByPk($data->member_network_id)->network_mid))',
                ),
                'login' => array(
                    'label' => 'Auto Login',
                    'imageUrl' => Yii::app()->request->baseUrl . '/images/icon/adm_login_navy.png',
                    'url' => 'Yii::app()->createUrl("admin/system/member/autologin", array("id" => sys_network::Model()->FindByPk($data->member_network_id)->network_mid))',
                    'options' => array('target' => '_blank'),
                ),
                'report' => array(
                    'imageUrl' => Yii::app()->request->baseUrl . '/images/icon/adm_edit2_navy.png',
                    'type' => 'raw',
                    'click' => 'function() {
                            var member_network_id = $(this).parent().parent().children(":nth-child(1)").text();
                            $("#div_content").load("report/"+member_network_id+"");
                            $("#dialog").dialog( "option", "width", 800 );
                            $("#dialog").dialog( "option", "height", 500 );
                            $("#dialog").dialog("open");
                            
                        }',
                ),
            ),
        ),
    ),
    'selectableRows' => 1,
    'selectionChanged' => 'userClicks',
    'pager' => array(
        'cssFile' => Yii::app()->params['backendUrl'] . '/css/style-pager.css',
        'header' => '',
        'firstPageLabel' => 'First',
        'prevPageLabel' => 'Previous',
        'nextPageLabel' => 'Next',
        'lastPageLabel' => 'Last',
    ),
    'cssFile' => Yii::app()->params['backendUrl'] . '/css/style-gridview.css',
    'loadingCssClass' => '',
));
?>
<script>
    var id = 0;
    var row = 0;
    function userClicks(target_id) {
        id = $.fn.yiiGridView.getSelection(target_id);
        //id = $.fn.yiiGridView.getKey(target_id, 2);
        //alert(id);
    }
    
    function clickReport(target_id) {
        id = $.fn.yiiGridView.getSelection(target_id);
        alert(id);
        return false;
    }
</script>

<div id="dialog" style="text-align: left;display: none; ">
    <div class="box grid_16">
        <a href="#" class="grabber">&nbsp;</a>
        <a href="#" class="toggle">&nbsp;</a>
        <div class="toggle_container">
            <div class="wizard">		
                <div class="wizard_steps">
                    <ul class="clearfix">
                        <li class="current">
                            <a href="#bonus" class="clearfix">
                                <span><strong>Summary Bonus</strong></span>

                            </a>
                        </li>
                        <li>
                            <a href="#ewallet" class="clearfix">
                                <span><strong>Statement Bonus</strong></span>

                            </a>
                        </li>
                        <li>
                            <a href="#network" class="clearfix">
                                <span><strong>Historis Withdrawal</strong></span>

                            </a>
                        </li>
                        <li>
                            <a href="#upgrade" class="clearfix">
                                <span><strong>Historis Upgrade</strong></span>

                            </a>
                        </li>
                    </ul>		
                </div>
            </div>
            <div id="div_content" class="block grid_16 alpha omega wizard_content">

            </div>
        </div>
    </div>
    <script type="text/javascript">
	
        // wizard
        $('.wizard_steps ul li a').click(function(){
	
            $('.wizard_steps ul li').removeClass('current');
            $(this).parent('li').addClass('current');
		
            var step = $(this).attr('href');
            var step_num = $(this).attr('href').replace('#step_','');
            var step_multiplyby = (100 / $(".wizard_steps > ul > li").size());
            var prog_val = (step_num*step_multiplyby);
		
            $( "#progressbar").progressbar({ value: prog_val });
		
            $('.wizard_content').children().hide();
            $('.wizard_content').children(step).fadeIn();
		
            return false;
        });
	
        $('button.next_step').click(function(){
		
            var step = $(this).attr('id');
            var hash_step = ('#'+step);
				
            var step_num = $(this).attr('id').replace('step_','');
            var step_multiplyby = (100 / $(".wizard_steps > ul > li").size());
            var prog_val = (step_num*step_multiplyby);
		
            $( "#progressbar").progressbar({ value: prog_val });
		
            $('.wizard_steps ul li').removeClass('current');
            $('a[href='+ hash_step +']').parent().addClass('current');
		
            $('.wizard_content').children().hide();
            $('.wizard_content').children(hash_step).fadeIn();
		
            return false;		
        });
	

    </script>

</div>
